package com.winter.pojo;

import com.winter.enums.ResponseType;
import lombok.Data;

/**
 * Author: Li
 * Date: 10/27/2025 00:56
 * Description: Response
 */
@Data
public class Response<T> {
    private String code;
    private String message;
    private T data;

    public Response(ResponseType responseType, String message, T data) {
        this.code = responseType.getCode();
        if(message == null) {
            this.message = responseType.getMessage();
        }else {
            this.message = message;
        }
        this.data = data;
    }

    public static <T> Response<T> success(T data) {
        return new Response<>(ResponseType.SUCCESS, null, data);
    }

    public static <T> Response<T> success() {
        return new Response<>(ResponseType.SUCCESS, null, null);
    }

    public static <T> Response<T> failed(String message, T data) {
        return new Response<>(ResponseType.FAILED, message, data);
    }

    public static <T> Response<T> failed(String message) {
        return new Response<>(ResponseType.FAILED, message, null);
    }

    public static <T> Response<T> failed() {
        return new Response<>(ResponseType.FAILED, null, null);
    }

    public static <T> Response<T> failed(ResponseType type) {
        return new Response<>(type, null, null);
    }

    public static <T> Response<T> failed(ResponseType type, T data) {
        return new Response<>(type, null, data);
    }

    public static <T> Response<T> failed(ResponseType type, String message) {
        return new Response<>(type, message, null);
    }
}
